﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using WebSEClassLibrary;

namespace WebSE
{
    public partial class Act : System.Web.UI.Page
    {
        protected ActPage actPage;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Session["currentPageNum"] = 9;
            }
            actPage = new ActPage((int)Session["currentPageNum"]);
            new_page(false);
            chat.Text = actPage.Problem;
        }

        //按上一步按钮的响应函数
        protected void previous_click(object sender, EventArgs e)
        {
            if (((int)Session["currentPageNum"]) > 1)
            {
                Session["currentPageNum"] = ((int)Session["currentPageNum"])-1;
                actPage = new ActPage(((int)Session["currentPageNum"]));
                new_page(true);
            }
        }

        //按下一步按钮的响应函数
        protected void next_click(object sender, EventArgs e)
        {
            //记录用户答案
            if (Page.User.Identity.Name != "") actPage.UserID = Page.User.Identity.Name;
            actPage.writeDataBase();

            Session["currentPageNum"] = ((int)Session["currentPageNum"]) + 1;
            actPage = new ActPage((int)Session["currentPageNum"]);
            new_page(false);
        }

        //显示新的页面
        protected void new_page(bool isPrePage)
        {
            //设置头像和谈话内容
            picture.ImageUrl = actPage.PicURL;
            chat.Text = actPage.ChatContent;
            
            //显示题目
            if(!actPage.IsChatPage)
            {
                Session["currentPage"] = actPage;
                switch (actPage.ProblemType)
                {
                    case 1:
                        frm1.Attributes["src"] = "Act1.aspx";
                        break;
                    case 2:
                        frm1.Attributes["src"] = "Act2.aspx";
                        break;
                    case 3:
                        if (actPage.CountFillAns == 1)
                            frm1.Attributes["src"] = "Act3_1.aspx";
                        else if (actPage.CountFillAns == 2)
                            frm1.Attributes["src"] = "Act3_2.aspx";
                        else if (actPage.CountFillAns == 3)
                            frm1.Attributes["src"] = "Act3_3.aspx";
                        else if (actPage.CountFillAns == 4)
                            frm1.Attributes["src"] = "Act3_4.aspx";
                        else break;
                        break;
                }
            }
        }
    }
}
